/**
 * 视图事件、手势的定义
 * 
 */

App.Event = (function($, App, undefined) {

    /**
     * 在不同的article间切换
     * @param {type} art
     * @param {type} step 往前或往后
     */
    var tabArticle = function(art, step) {
        var id = art.id;
        var parent = art.parentNode;
        if (parent.nodeName === 'SECTION') {
            var section_id = parent.id;
            var childs = parent.children;
            var prevArt = null;
            var idx = 0;
            var isNext = false;
            for (key in childs) {
                var child = childs[key];
                if (child.nodeName === 'ARTICLE') {
                    if (isNext) {
                        App.Router.gotoArticle(section_id, child.id);
                        return;
                    } else if (child.id === id) {
                        if (step === -1 && prevArt) {
                            App.Router.gotoArticle(section_id, prevArt.id);
                            return;
                        } else if (step === 1) {
                            isNext = true;
                        }
                    }
                    prevArt = child;
                }
            }
        }
    };

    return {
        tabArticle: tabArticle,
    };

})(Lungo.dom, App);

Lungo.Events.init({
    // 'swipeRight section#home article' : function() {
    // App.Event.tabArticle(this, -1);
    // },
    // 'swipeLeft section#home article' : function() {
    // App.Event.tabArticle(this, 1);
    // },

    // 'swipeRight section' : function() {
    // if (this.id != 'home' && this.id!='question') {
    // App.View.goBack();
    // }
    // },
    // 'swipeRight section#question article' : function() {
    // App.Presenter.QuestionPagePresenter.prevQuestion();
    // },
    // 'swipeLeft section#question article' : function() {
    // App.Presenter.QuestionPagePresenter.nextQuestion();
    // },

});
